<template>
  <a-form
      :model="formState"
      layout="inline"
  >
    <a-row style="width:100%">
      <a-col :xl="8" :lg="9" :md="12" :sm="24" :xs="24">
        <a-form-item label="仓库SKU">
          <a-input  v-model:value="formState.warehouseSku"/>
        </a-form-item>
      </a-col>
      <a-col :xl="8" :lg="9" :md="12" :sm="24" :xs="24">
        <a-form-item label="站点">
          <a-select v-model:value="formState.site" :options="options" allow-clear/>
        </a-form-item>
      </a-col>
      <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
        <a-form-item>
          <a-button type="primary" style="margin-right: 10px;" @click="handleSearch">查询</a-button>
          <a-button type="primary" @click="reset">重置</a-button>
        </a-form-item>
      </a-col>
    </a-row>
  </a-form>
  <common-table
      v-if="dataList && dataList.length > 0"
      :columns="columns"
      :dataSource="dataList"
      :scroll="{ x: 'max-content'}"
  ></common-table>
</template>
<script setup>
import { ref,reactive } from "vue";
import CommonTable from "@/components/commonTable/index.vue";
import {getManyDictItems} from "@/api/system/dict.js";
import {getInventorySkuList} from "@/api/firstShipping/skuInventory.js";
import {message} from "ant-design-vue";
const columns = [
  {

    "dataIndex": "site",
    "title": "站点",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "warehouseCode",
    "title": "目的仓",
    "align": "center",
    "fieldType": "Date"
  },
  {
    "dataIndex": "warehouseSku",
    "title": "仓库SKU",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "qty",
    "title": "数量",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "usedQty",
    "title": "已使用数量",
    "align": "center",
    "fieldType": "Date"
  },
  {

    "dataIndex": "availableQty",
    "title": "可用数量",
    "align": "center",
    "fieldType": "Date"
  },
  {

    "dataIndex": "poolType",
    "title": "库存池类型",
    "align": "center",
    "fieldType": "Date"
  },
  {

    "dataIndex": "poolCode",
    "title": "库存池编码",
    "align": "center",
    "fieldType": "Date"
  }
]
const dataList = ref([])
const options = ref([])
const formState = reactive({
  warehouseSku: "",
  site: "",
})
const handleSearch = async () => {
  try{
    if(formState.site === null || formState.site === undefined){
      formState.site = ""
    }
    if(formState.warehouseSku === ''){
      return message.error("仓库SKU不能为空")
    }
    const res = await getInventorySkuList(formState)
    dataList.value = res.result.records
    console.log(res)
  }catch (e){
    message.error(e)
  }
}
const reset = () => {
  formState.warehouseSku = ""
  formState.site = ""
}
/**
 * 初始化字典数据
 * @returns {Promise<void>}
 */
const init = async () => {
  try{
    const res = await getManyDictItems({
      dictCodeList:"site"
    })
    options.value = res.result.site
  }catch (e){
    console.log(e)
  }
}
init()
</script>
<style scoped>

</style>
